package com.kly.sc.api.application.controller.user.request;

import com.fqgj.common.api.ParamsObject;
import com.kly.sc.api.infras.exception.ApplicationException;
import com.kly.sc.api.infras.utils.StringUtils;
import com.kly.user.enums.ImageOpTypeEnum;
import com.kly.user.enums.ImageType;

/**
 * 用户照片
 * @author linqu
 */
public class ChangeImagesRequest extends ParamsObject {

    /**
     * 操作类型：1-新增 2-修改 3-删除
     */
    private Integer opType;

    /**
     * 照片内码
     */
    private String imageCode;
    /**
     * 照片
     */
    private String imageUrl;
    /**
     * 相册类型
     */
    private Integer type;
    /**
     * 视频长度，添加照片该字段无值
     */
    private Integer videoLength;

    /**
     * 头像标志：1-是 0-否
     */
    private Integer avatarFlag;

    public Integer getAvatarFlag() {
        return avatarFlag;
    }

    public void setAvatarFlag(Integer avatarFlag) {
        this.avatarFlag = avatarFlag;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getImageCode() {
        return imageCode;
    }

    public void setImageCode(String imageCode) {
        this.imageCode = imageCode;
    }

    public String getImageUrl() {
        return imageUrl;
    }

    public void setImageUrl(String imageUrl) {
        this.imageUrl = imageUrl;
    }

    public Integer getVideoLength() {
        return videoLength;
    }

    public void setVideoLength(Integer videoLength) {
        this.videoLength = videoLength;
    }

    public Integer getOpType() {
        return opType;
    }

    public void setOpType(Integer opType) {
        this.opType = opType;
    }

    @Override
    public void validate() {

        if (ImageOpTypeEnum.fromType(this.opType) == null) {
            throw new ApplicationException("The parameter [opType] is empty or Illegal parameter");
        }
        if (ImageType.fromType(this.type) == null) {
            throw new ApplicationException("The parameter [type] is empty or Illegal parameter");
        }

        if (StringUtils.isEmpty(this.imageUrl)) {
            throw new ApplicationException("The parameter [imageUrl] is empty");
        }
        if (ImageOpTypeEnum.change.getType().equals(this.opType) || ImageOpTypeEnum.remove.getType().equals(this.opType)) {
            if (StringUtils.isEmpty(this.imageCode)) {
                throw new ApplicationException("The parameter [imageCode] is empty");
            }
        }

        if (ImageType.VIDEO.getType() == this.type && this.videoLength == null) {
            throw new ApplicationException("The parameter [videoLength] is empty");
        }
        this.videoLength = this.videoLength == null ? 0 : this.videoLength;
    }


}
